const { defineConfig } = require('@vue/cli-service')
// const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const Mock = require("mockjs");
const bodyParser = require("body-parser");
const data = Mock.mock({
  "data|10": [
    {
      id: "@id",
      title: "@cword(3,5)",
      img: "@image(300x100,@color)",
    }
  ],
  code: 200
})
module.exports = defineConfig({
  // configureWebpack: {
  //   plugins: [new NodePolyfillPlugin()],
  // },
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    onBeforeSetupMiddleware({ app }) {
      app.use(bodyParser.json());
      app.post('/logins', (req, res) => {
        const { username, password } = req.body;
        if (username == "admin" && password == "123456") {
          return res.json({
            meta: "登录成功",
            success: true,
            userInfo: {
              nickname: "明阳"
            }
          })
        }
        res.json({
          meta: "登录失败",
          success: false,
          userInfo: null,
        })
      })
      app.get('/list', (req, res) => {
        res.json(data);
      })
    }
  }
})
